package cn.com.yusys.yusp.admin.web.rest;

import cn.com.yusys.yusp.admin.Utils.Result;
import cn.com.yusys.yusp.admin.service.GridGeneralService;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0.0
 * @项目名称: yusp-admin
 * @类名称: SystemLogResource
 * @类描述: 网格概览功能
 * @功能描述:
 * @创建人:
 * @创建时间: 2021-5-26
 * @修改备注:
 * @修改记录: 修改时间    修改人员    修改原因
 * -------------------------------------------------------------
 * @Copyright (c) 2017宇信科技-版权所有
 */
@RestController
@RequestMapping("/api/gridGeneral")
public class GridGeneralResource {

    @Autowired
    private GridGeneralService gridGeneralService;
    /**
     * 根据机构号查询一级网格
     */
    @GetMapping("/oneLevelGrid")
    public ResultDto<List<Map<String, Object>>> getOneLevelGrid(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryOneLevel(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }

    /**
     * 根据一级网格ID查询二级网格
     */
    @GetMapping("/twoLevelGrid")
    public ResultDto<List<Map<String, Object>>> getTwoLevelGrid(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryTwoLevel(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }

    /**
     * 根据用户ID查询二级网格及三级网格
     */
    @GetMapping("/thirdLevelGrid")
    public ResultDto<List<Map<String, Object>>> getThirdLevelGrid(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryThirdLevel(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }

    /**
     * 无参查询所有一级网格
     */
    @GetMapping("/onlyOneLevelGrid")
    public ResultDto<List<Map<String, Object>>> getOnlyOneLevelGrid(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryOnlyOneLevel(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }

    /**
     * 机构ID查询一级网格及该网格下的二级网格
     */
    @GetMapping("/oneLevelGridByOrgId")
    public ResultDto<List<Map<String, Object>>> getOneLevelGridByOrgId(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryOneLevelByOrgId(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }
    /**
     * 机构ID查询一级网格及该网格下的二级网格
     */
    @GetMapping("/twoLevelGridByUserId")
    public ResultDto<List<Map<String, Object>>> getTwoLevelGridByUserId(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryTwoLevelGridByUserId(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }

    /**
     * 取第一个点去后台判断是哪个网格内的二级网格，取出上级网格ID，并写入到上级网格中去 要区分客户经理和支行、行长
     * 支行和行长：查询所有1级网格，遍历check点是否在网格内，在则返回1级网格ID和网格名称
     * 客户经理：查询此客户经理的二级网格，遍历check点是否在网格内，在则返回二级级网格ID和网格名称
     */
    @GetMapping("/checkGripOnPolygon")
    public ResultDto<List<Map<String, Object>>> checkGripOnPolygon(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.checkGripOnPolygon(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }


    /**
     * 一级二级网格新建保存
     * @param map
     * @return
     */
    @PostMapping("/saveGridData")
    public ResultDto<Integer> cliamData(@RequestBody Map map) {
        Integer result = gridGeneralService.saveGridData(map);
        return new ResultDto<>(result);
    }

    /**
     * 无参查询所有一级网格---网格名选择
     */
    @GetMapping("/onlyOneLevelGridModify")
    public ResultDto<List<Map<String, Object>>> getOnlyOneLevelGridModify(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryOnlyOneLevelModify(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }
    /**
     * 根据网格Name查询网格备注
     */
    @GetMapping("/querySecByGridName")
    public ResultDto<List<Map<String, Object>>> querySecByGridName(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.querySecByGridName(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }
    /**
     * 根据选择内容定位gridId
     */
    @GetMapping("/modifyPolygon")
    public ResultDto<List<Map<String, Object>>> queryModifyPolygon(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryModifyPolygon(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }
    /**
     * 保存修改信息
     */
    @PostMapping("/updataPolygonInfo")
    public ResultDto<Integer> updataPolygonInfo(@RequestBody Map map) {
        Integer result = gridGeneralService.updataPolygonInfo(map);
        return new ResultDto<>(result);
    }

    /**
     * 机构ID查询该网格下的二级网格
     */
    @GetMapping("/onlyTwoLevelGridModify")
    public ResultDto<List<Map<String, Object>>> getOnlyTwoLevelGridModify(QueryModel queryModel) {
        List<Map<String, Object>> list = gridGeneralService.queryOnlyTwoLevelGridModify(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }

    /**
     * 网格信息配置查询table数据
     * 需根据不同角色进行划分 1、总行管理 查看全部 1级网格 2、支行查看本支行所有的2级网格可做修改 补齐房价户数等信息3、客户经理查看分配给自己的网格信息，可进行网格关键人信息，建筑物信息的补齐
     *
     */
    @GetMapping("/gridTableSelect")
    public ResultDto<Object> selectLoanTraceList(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.selectGridTableList(queryModel));
    }

    /**
     * 根据网格id查询网格基本信息
     */
    @GetMapping("/queryGridInfoById")
    public ResultDto<Object> queryGridInfoById(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryGridInfoById(queryModel));
    }

    /**
     * 根据网格id查询网格基本信息
     */
    @GetMapping("/queryGridKeyManById")
    public ResultDto<Object> queryGridKeyManById(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryGridKeyManById(queryModel));
    }

    /**
     * 保存网格基本信息
     */
    @PostMapping("/updateGridInfoById")
    public ResultDto<Object> updateGridInfoById(@RequestBody Map map){
        return new ResultDto<>(gridGeneralService.updateGridInfoById(map));
    }

    /**
     * 保存关键人信息
     */
    @PostMapping("/saveKeyManGridData")
    public ResultDto<Object> saveKeyManGridData(@RequestBody Map map){
        return new ResultDto<>(gridGeneralService.saveKeyManGridData(map));
    }

    /**
     * 保存客户经理分配信息
     */
    @PostMapping("/saveMgrFPGridData")
    public ResultDto<Object> saveMgrFPGridData(@RequestBody Map map){
        return new ResultDto<>(gridGeneralService.saveMgrFPGridData(map));
    }

    /**
     * 保存建筑物信息
     */
    @PostMapping("/saveBuildInfoGridData")
    public Result<String> saveBuildInfoGridData(@RequestBody Map map){
        return gridGeneralService.saveBuildInfoGridData(map);
    }

    /**
     * 根据ID查询建筑物信息
     */
    @GetMapping("/queryGridBuildById")
    public ResultDto<Object> queryGridBuildById(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryGridBuildById(queryModel));
    }

    /**
     * 根据ID和等级查询网格业绩信息
     */
    @GetMapping("/oneLevelGridInfo")
    public ResultDto<Object> oneLevelGridInfo(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryOneLevelGridInfo(queryModel));
    }

    @GetMapping("/oneLevelGridInfoCustNum")
    public ResultDto<Object> oneLevelGridInfoCustNum(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryOneLevelGridInfoCustNum(queryModel));
    }

    @GetMapping("/queryOneLevelGridInfoCustNumChange")
    public ResultDto<Object> queryOneLevelGridInfoCustNumChange(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryOneLevelGridInfoCustNumChange(queryModel));
    }

    @GetMapping("/twoLevelGridInfo")
    public ResultDto<Object> twoLevelGridInfo(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryTwoLevelGridInfo(queryModel));
    }

    @GetMapping("/twoLevelGridInfoCustNum")
    public ResultDto<Object> twoLevelGridInfoCustNum(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryTwoLevelGridInfoCustNum(queryModel));
    }

    @GetMapping("/queryTwoLevelGridInfoCustNumChange")
    public ResultDto<Object> queryTwoLevelGridInfoCustNumChange(QueryModel queryModel){
        return new ResultDto<>(gridGeneralService.queryTwoLevelGridInfoCustNumChange(queryModel));
    }

    /**
     * 根据ID批量删除关键人信息
     */
    @DeleteMapping("/deletebatch")
    public Result<String> deleteBatch(@RequestParam String id) {
        return gridGeneralService.deleteBatch(id);
    }

    /**
     * 根据ID批量删除建筑物信息
     */
    @DeleteMapping("/deletebatchBuild")
    public Result<String> deletebatchBuild(@RequestParam String id) {
        return gridGeneralService.deletebatchBuild(id);
    }

    /**
     * 适用客群 批量导入
     * @param multipartFile
     * @param prodNum
     * @return
     * @throws IOException
     */
    @PostMapping("/excel/import") //
    public ResultDto<String> importExcel(@RequestParam(value="file",required = false) MultipartFile multipartFile) throws IOException {
        return null;
    }
}
